package com.wtzz.police.base.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiModelProperty.AccessMode;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@Setter
@Getter
public abstract class AbstractTimeEntity extends AbstractIdEntity implements Serializable {

    @ApiModelProperty(value = "创建时间", accessMode = AccessMode.READ_ONLY, example = "yyyy-MM-dd HH:mm:ss", readOnly = true)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @CreatedDate
    @Column(name = "created_date", nullable = false, columnDefinition = "datetime(3)")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate = new Date();

    @ApiModelProperty(value = "修改时间", accessMode = AccessMode.READ_ONLY, example = "yyyy-MM-dd HH:mm:ss", readOnly = true)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @LastModifiedDate
    @Column(name = "modified_date", columnDefinition = "datetime(3)")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modifiedDate = new Date();

}